﻿namespace Budgetsch.WP7.ViewModel.Setting
{
    using GalaSoft.MvvmLight;

    using System.Windows.Input;

    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class ToggleButtonViewModel : ViewModelBase
    {
        /// <summary>
        /// The <see cref="Text" /> property's name.
        /// </summary>
        public const string TextPropertyName = "Text";

        private string _text = "Non public";

        /// <summary>
        /// Sets and gets the Text property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public string Text
        {
            get
            {
                return _text;
            }

            set
            {
                _text = value;
                RaisePropertyChanged(TextPropertyName);
            }
        }

        public string HeaderText { get; set; }

        /// <summary>
        /// The <see cref="IsChecked" /> property's name.
        /// </summary>
        public const string IsCheckedPropertyName = "IsChecked";

        private bool _isChecked;

        /// <summary>
        /// Sets and gets the IsChecked property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public bool IsChecked
        {
            get
            {
                return this._isChecked;
            }

            set
            {
                if (this._isChecked == value)
                {
                    return;
                }

                _isChecked = value;

                this.Text = this._isChecked ? "Public" : "Non public";
                RaisePropertyChanged(IsCheckedPropertyName);
            }
        }

        public ICommand ClickCommand { get; set; }
        
        /// <summary>
        /// Initializes a new instance of the ToggleButtonViewModel class.
        /// </summary>
        public ToggleButtonViewModel(string headerText, bool startValue)
        {
            HeaderText = headerText;
            IsChecked = startValue;
        } 
    }
}